package com.taldh.algorithm.动态规划;

import org.junit.Assert;
import org.junit.Test;

public class MinCostClimbingStairs {

    public int minCostClimbingStairs(int[] cost) {
        if ( cost == null || cost.length < 1) {
            return 0;
        }
        if (cost.length < 2) {
            return cost[0];
        }
        int ans0 = 0;
        int ans1 = 0;

        for (int j = cost.length - 1; j >= 0; j--) {
            int ans = Math.min(ans0, ans1)+cost[j];
            ans0 = ans1;
            ans1 = ans;
        }
        return Math.min(ans0, ans1);
    }

    @Test
    public void test() {
        Assert.assertEquals(6, minCostClimbingStairs(new int[]{1, 100, 1, 1, 1, 100, 1, 1, 100, 1}));
    }

    @Test
    public void test1() {
        Assert.assertEquals(2, minCostClimbingStairs(new int[]{0, 1, 2, 2}));
    }
}